<style lang="less">
@import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
export default {
	components: {
		LoginForm,
	},
	methods: {
		...mapActions(['handleLogin', 'getUserInfo']),
		handleSubmit({ userName, password }) {
			this.handleLogin({ userName, password }).then(res => {
				if (res.code == 0) {
					let user = {}
					user.username = userName
					user.id = res.id
					user.token = res.Authorization
          user.type = res.type
          user.icon = res.icon
          user.role = res.role
          user.first_access = res.first_access
          localStorage.setItem('user', JSON.stringify(user))
          localStorage.setItem('user_role', JSON.stringify(user.role))
          localStorage.setItem('phone_status', JSON.stringify(user.phone_status))
					// 头像固定
					this.$store.commit(
						'setAvator',
						res.icon,
					)
                    if (res.role == '超级管理员') {
                		window.location.href = '/admin-view/home'
                	} else {
                		//console.log(res.first_access);return false;
                		let routeData = this.$router.resolve({name: res.first_access})
                		window.location.href = routeData.href
                	}
				} else {
					this.$Notice.error({
						title: '登录提示',
						desc: res.text,
						duration: 2,
					})
				}
			})
		},
	},
}
</script>

<style>
</style>
